package
{
    import com.greensock.TweenMax;

    import flash.display.Sprite;
    import flash.events.Event;

    import gravity.Box;

    [SWF(height="600", frameRate="48", backgroundColor="0xFFFFFF")]
    public class GravityMain extends Sprite
    {

        private var box1:Box;
        private var box2:Box;

        public function GravityMain()
        {
            super();
            this.addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
            //this.addEventListener(Event.ENTER_FRAME, enterFrameHandler, false, 0, true);
        }

        private function init(event:Event):void
        {
            box1 = new Box
            box1.x = 0;
            box1.y = 0;
            this.addChild(box1);
            TweenMax.to(box1, 3, {y: stage.stageHeight, onComplete: tweenOnComplete, onCompleteParams: [box1]});

            box2 = new Box
            box2.x = 60;
            box2.y = 0;
            this.addChild(box2);
            TweenMax.to(box2, 3, {y: stage.stageHeight, onComplete: tweenOnComplete, onCompleteParams: [box2]});
        }
        private var cnt:int = 0;

        private function tweenOnComplete(value:Box):void
        {
            if(value.upDown)
            {
                TweenMax.to(value, 3, {y: (value.height * cnt), onComplete: tweenOnComplete, onCompleteParams: [value]});
                cnt++;
                value.upDown = !value.upDown;
            }
            else
            {
                TweenMax.to(value, 3, {y: stage.stageHeight, onComplete: tweenOnComplete, onCompleteParams: [value]});
                value.upDown = !value.upDown;
            }
        }
    }
}